﻿<Window x:Class="mskold.TfsAdminToolKit.Views.TestAttachmentSize"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="clr-namespace:mskold.TfsAdminToolKit.ViewModels"
        xmlns:src="clr-namespace:Sogeti.SourceControlWrapper"
        xmlns:my="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.11.0"
        Title="TestAttachmentSize" Height="900" Width="800" >

    <Window.DataContext >
        <vm:TestAttachmentViewModel />
    </Window.DataContext>
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key = "BooleanToVisibilityConverter"/>
        <Style x:Key="RightAlignCell" TargetType="{x:Type DataGridCell}">
            <Setter Property="HorizontalAlignment" Value="Right"/>
        </Style>
        <!--<HierarchicalDataTemplate DataType="{x:Type src:SCFolder}"   ItemsSource="{Binding Path=Folders}">
            <StackPanel Orientation="Horizontal">
                <Label Name="tvNode" Padding="2" Content="{Binding Path=FolderName}" />
                <Label Name="lblSize" Padding="2" Content="{Binding Path=SizeTxt}" />
            </StackPanel>
            <HierarchicalDataTemplate.Triggers>

            </HierarchicalDataTemplate.Triggers>
        </HierarchicalDataTemplate>-->
        <src:DivideBy2Converter x:Key="DivideBy2Converter" />
        <src:FileSizeConverter x:Key="FileSizeConverter" />

        <Style x:Key="StretchItem" TargetType="{x:Type StackPanel}">
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
        </Style>
        <Style x:Key="BoldText" TargetType="{x:Type Label}">
            <Setter Property="FontWeight" Value="Bold"/>
        </Style>

        <HierarchicalDataTemplate x:Key="NodeTemplate" >
            <!--<TreeViewItem x:Name="tvNode" Header ="{Binding XPath=@Name}" IsHitTestVisible="True" IsTabStop="True" IsSelected="{Binding XPath=@IsSelected, Mode=TwoWay}" Focusable="True"/>-->
            <StackPanel Orientation="Horizontal"  Style="{StaticResource StretchItem}">
                <Label Name="tvNode" HorizontalAlignment="Left" Width="{Binding Path=ActualWidth, Converter={StaticResource DivideBy2Converter}, ConverterParameter=0.6, RelativeSource={RelativeSource FindAncestor, AncestorType=TreeView, AncestorLevel=1}}" Padding="2" Content="{Binding Path=FolderName}" />
                <Label Name="lblSize" HorizontalAlignment="Right" Width="60" Padding="2" Content="{Binding Path=SizeTxt}" HorizontalContentAlignment="Right" />
            </StackPanel>
            <HierarchicalDataTemplate.ItemsSource>
                <Binding Path="Folders" />
            </HierarchicalDataTemplate.ItemsSource>
        </HierarchicalDataTemplate>

        <my:BooleanToHiddenVisibilityConverter x:Key="BooleanToHiddenVisibilityConverter1" />
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter1" />
    </Window.Resources>

    <Grid >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>

        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"  />
            <RowDefinition Height="*"     />
            <RowDefinition Height="0"  />
            <RowDefinition Height="250"/>
            <RowDefinition Height="6"/>
        </Grid.RowDefinitions>
        <Expander Grid.Row="0" Header="Totals" Margin="12,0,6,12" Visibility="{Binding Path=TotalExist, Mode=OneWay, Converter = {StaticResource BooleanToVisibilityConverter}}" IsExpanded="True"  >
            <StackPanel Grid.ColumnSpan="2" Name="stpTotal" Visibility="{Binding Path=TotalExist, Mode=OneWay, Converter = {StaticResource BooleanToVisibilityConverter}}" Margin="12,12,12,0" >
                <StackPanel Orientation="Horizontal">
                    <Label Content="Total Test attachments size: " Height="28" Name="label2" Style="{StaticResource BoldText}" />
                    <Label Content="{Binding Path=TotalAttachments.SizeTxt}" Height="28" Name="lblTotalSize" Style="{StaticResource BoldText}" />
                </StackPanel >
                <StackPanel Orientation="Horizontal" MinHeight="100" >
                    <DataGrid  AutoGenerateColumns="False" GridLinesVisibility="None" IsReadOnly="True" MinWidth="200" ItemsSource="{Binding Path=TotalAttachments.FileExt}" Name="dgrTotalFileExt" MinHeight="60">
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding Path=Key}" Header="Extension" IsReadOnly="True" />
                            <DataGridTextColumn Binding="{Binding Path=Value, Converter={StaticResource FileSizeConverter}, Mode=OneTime}" CellStyle="{StaticResource RightAlignCell}" Header="Size" IsReadOnly="True" />
                        </DataGrid.Columns>
                    </DataGrid>
                    <DataGrid AutoGenerateColumns="False" HorizontalAlignment="Stretch" Margin="6,0,12,12" MinWidth="200" Name="dgrTotalAttachment" VerticalAlignment="Stretch" ItemsSource="{Binding Path=TotalAttachments.AttachmentTypes}" IsReadOnly="True" GridLinesVisibility="None" MinHeight="60">
                        <DataGrid.Columns>
                            <DataGridTextColumn IsReadOnly="True" Header="AttachmentType" Binding="{Binding Path=Key}" />
                            <DataGridTextColumn IsReadOnly="True" Header="Size" Binding="{Binding Path=Value, Converter={StaticResource FileSizeConverter}, Mode=OneTime}" CellStyle="{StaticResource RightAlignCell}" />
                        </DataGrid.Columns>
                    </DataGrid>
                    <DataGrid AutoGenerateColumns="False" HorizontalAlignment="Stretch" x:Name="dgrTotalTime" VerticalAlignment="Stretch" ItemsSource="{Binding Path=TotalAttachments.Time}" IsReadOnly="True" GridLinesVisibility="None" >
                        <DataGrid.Columns>
                            <DataGridTextColumn IsReadOnly="True" Header="Time" Binding="{Binding Key}" />
                            <DataGridTextColumn IsReadOnly="True" Header="Size" Binding="{Binding Value, Converter={StaticResource FileSizeConverter}, Mode=OneTime}" CellStyle="{StaticResource RightAlignCell}" />
                        </DataGrid.Columns>
                    </DataGrid>
                </StackPanel>

            </StackPanel>
        </Expander>
        <Button Content="Start" Name="cmdStart" Width="100px" Height="32" Click="cmdStart_Click" Margin="0,12,12,0" VerticalAlignment="Top" HorizontalAlignment="Right" Visibility="{Binding Path=Progress.ShowForm, Mode=OneWay, Converter = {StaticResource BooleanToVisibilityConverter}}" />

        <ProgressBar Grid.Column="0" Grid.Row="0" Height="16"  HorizontalAlignment="Stretch" Name="progressBar"  VerticalAlignment="Top" Value="{Binding Path=Progress.JobProgress, Mode=OneWay, IsAsync=True}" Visibility="{Binding Path=Progress.ShowProgress, Mode=OneWay, Converter = {StaticResource BooleanToVisibilityConverter}}" Maximum="{Binding Path=Progress.Max, Mode=OneWay}" Margin="12,12,12,0"/>
        <Label Grid.Column="0" Grid.Row="0"  HorizontalAlignment="Stretch" Content="{Binding Path=Progress.CurrentOperation}"  Padding="0" Name="lblProgress" VerticalAlignment="Top" FontSize="10" Opacity="1" HorizontalContentAlignment="Center" Visibility="{Binding Path=Progress.ShowProgress, Mode=OneWay, Converter = {StaticResource BooleanToVisibilityConverter}}" Margin="12,12,12,0"/>
        <GridSplitter ResizeDirection="Rows" Grid.Column="0" Grid.Row="1" Width="Auto" Height="3" HorizontalAlignment="Stretch" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="1"/>

        <Grid Grid.Row="1" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="2*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"         />
                <RowDefinition Height="2*"         />
                <RowDefinition Height="*"         />
            </Grid.RowDefinitions>


            <DataGrid AutoGenerateColumns="False" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" Margin="6,0,12,12" Name="dataGrid1" VerticalAlignment="Stretch" ItemsSource="{Binding Path=SelectedItem.FileExt, ElementName=dgrProjects}" IsReadOnly="True" GridLinesVisibility="None">
                <DataGrid.Columns>
                    <DataGridTextColumn IsReadOnly="True" Header="Extension" Binding="{Binding Path=Key}" />
                    <DataGridTextColumn IsReadOnly="True" Header="Size" Binding="{Binding Path=Value, Converter={StaticResource FileSizeConverter}, Mode=OneTime}" CellStyle="{StaticResource RightAlignCell}" />
                </DataGrid.Columns>
            </DataGrid>

            <DataGrid AutoGenerateColumns="False" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" Margin="6,0,12,12" Name="dataGrid3" VerticalAlignment="Stretch" ItemsSource="{Binding Path=SelectedItem.AttachmentTypes, ElementName=dgrProjects}" IsReadOnly="True" GridLinesVisibility="None">
                <DataGrid.Columns>
                    <DataGridTextColumn IsReadOnly="True" Header="AttachmentType" Binding="{Binding Path=Key}" />
                    <DataGridTextColumn IsReadOnly="True" Header="Size" Binding="{Binding Path=Value, Converter={StaticResource FileSizeConverter}, Mode=OneTime}" CellStyle="{StaticResource RightAlignCell}" />
                </DataGrid.Columns>
            </DataGrid>

            <DataGrid AutoGenerateColumns="False" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Stretch" Margin="6,0,12,12" Name="dgrTime" VerticalAlignment="Stretch" ItemsSource="{Binding Path=SelectedItem.Time, ElementName=dgrProjects}" IsReadOnly="True" GridLinesVisibility="None">
                <DataGrid.Columns>
                    <DataGridTextColumn IsReadOnly="True" Header="Time" Binding="{Binding Path=Key}" />
                    <DataGridTextColumn IsReadOnly="True" Header="Size" Binding="{Binding Path=Value, Converter={StaticResource FileSizeConverter}, Mode=OneTime}" CellStyle="{StaticResource RightAlignCell}" />
                </DataGrid.Columns>

            </DataGrid>

            <DataGrid AutoGenerateColumns="False"  Grid.Row="0" Grid.RowSpan="3" HorizontalAlignment="Stretch" Margin="12,0,6,12" Name="dgrProjects" VerticalAlignment="Stretch" ItemsSource="{Binding Path=RootFolder, Mode=TwoWay}" GridLinesVisibility="None" CanUserAddRows="True" CanUserDeleteRows="True" SelectionMode="Extended" IsReadOnly="True" SelectedItem="{Binding SelectedProject, UpdateSourceTrigger=PropertyChanged}">
                <DataGrid.ContextMenu>
                    <ContextMenu>
                        <MenuItem Command="Copy">
                            <!--<MenuItem.Icon>
                            <Image Source="Resources/copy.png" />
                        </MenuItem.Icon>-->
                        </MenuItem>

                    </ContextMenu>
                </DataGrid.ContextMenu>
                <DataGrid.Columns>
                    <DataGridTemplateColumn >
                        <DataGridTemplateColumn.HeaderStyle>
                            <Style TargetType="DataGridColumnHeader">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="DataGridColumnHeader">
                                            <CheckBox x:Name="chkAll" Content="" HorizontalAlignment="Center" VerticalAlignment="Center" Checked="chkAll_Checked" Unchecked="chkAll_Checked" />
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </DataGridTemplateColumn.HeaderStyle>

                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTextColumn Binding="{Binding Path=TeamProjectName}" Header="Teamproject " />
                    <DataGridTextColumn Binding="{Binding Path=SizeTxt}" Header="Size" SortMemberPath="Size" CellStyle="{StaticResource RightAlignCell}" />
                </DataGrid.Columns>
            </DataGrid>
        </Grid>
        <Expander Grid.Row="2" Header="Clean Test Attachments " Margin="12,0,6,4" Height="240" Grid.RowSpan="3">
            <StackPanel HorizontalAlignment="Stretch"  Name="stackPanel1" VerticalAlignment="Top" Height="250">

                <Label Content="The Test Attachement Cleaner Powertool was not found. Donwload from http://visualstudiogallery.msdn.microsoft.com/  " Height="28" Name="label1" Visibility="{Binding Path=NoTestAttachmentPowerToolInstalled, Converter={StaticResource BooleanToHiddenVisibilityConverter1}}" />
                <StackPanel Grid.Row="1" Height="200" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="stackPanel2" VerticalAlignment="Top" >
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition/>

                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Label Grid.Row="0" Grid.ColumnSpan="3" Content="Clean attatchment for seleted projects : " Height="28" Name="lblClean" />

                        <Label Grid.Row="1" Content="Mode : " Height="28" />
                        <ComboBox Grid.Row="1"  Grid.Column="1" Height="23" Name="cboMode" HorizontalAlignment="Stretch" Margin="0,0,0,0" MinWidth="245" ItemsSource="{Binding Path=TestCleanerModes}" SelectedValue="{Binding Path=SelectedMode}" />
                        <Label Grid.Row="2" Content="Configfile : " Height="28" />
                        <ComboBox Grid.Row="2"  Grid.Column="1" Height="23" Name="comboBox1"  ItemsSource="{Binding Path=TestCleanerConfigs}" HorizontalAlignment="Stretch" Margin="0,0,0,0" MinWidth="245" SelectedValue="{Binding Path=SelectedConfig}" />
                        <Label Grid.Row="3" Content="Override settings : " Height="28" />

                        <StackPanel Grid.Row="3"  Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Left" Height="28" VerticalAlignment="Center">
                            <CheckBox   Content="Age" Height="28" IsChecked="{Binding OverrideDate}"/>
                            <TextBox Height="28" TextWrapping="Wrap" Text="{Binding OverrideDateStart}" VerticalAlignment="Top" Width="32"/>
                            <Label Height="28" Content="-" />
                            <TextBox Height="28" TextWrapping="Wrap" Text="{Binding OverrideDateEnd}" VerticalAlignment="Top" Width="32"/>
                            <Label Height="28" Content=" Split over " />
                            <TextBox Height="28" TextWrapping="Wrap" Text="{Binding OverrideDateRuns}" VerticalAlignment="Top" Width="32"/>
                            <Label Height="28" Content=" runs " />
                        </StackPanel>
                        <StackPanel Grid.Row="4"  Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Left" >
                            <CheckBox   Content="Filetypes " Height="28" IsChecked="{Binding OverrideExtensions}" />

                            <ItemsControl ItemsSource="{Binding OverrideFileExt}"  >

                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Horizontal"/>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <CheckBox Content="{Binding Key}" IsChecked="{Binding isSelected}" />
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                            

                        </StackPanel>

                        <StackPanel Grid.Row="5"  Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center">
                            <Button   Content="Start clean" Height="23" Name="cmdDoClean" Width="178" Click="cmdDoClean_Click" Margin="12,6,6,12" IsEnabled="{Binding Path=TestAttachmentPowerToolInstalled}"/>
                            <Button   Content="Copy commands to clipboard" Height="23" Name="cmdCopyCommandToClipboard" Width="178" Margin="12,6,6,12" Click="cmdCopyCommandToClipboard_Click" />
                        </StackPanel>

                    </Grid>


                </StackPanel>

            </StackPanel>
        </Expander>
    </Grid>
</Window>
